<?php
if (eregi("sitemap.php",$_SERVER['SCRIPT_NAME'])) {
    Header("Location: ../index.php");
    die();
}

$text.=getRoot()."[list=disc]".getChild()."[/list=disc]";

function getRoot() {
  global $table,$db,$lang;
  $str = "";
  $result = $db->query("SELECT * FROM $table->page WHERE dir='0' AND language='$lang->current' ORDER BY id");
  while ($row = $db->nextRecord($result))
  {
    $str.= "[*][url=$row->id]$row->name[/url]\n";
  }
  return$str;
}

function getChild($parent = 0, $depth = 1) {
  global $db,$table,$lang;
  $str = "";
  $result = $db->query("SELECT * FROM $table->dir WHERE parent='$parent' AND language='$lang->current' ORDER BY id");
  while ($row = $db->nextRecord($result))
  {
    $str.="[*][b]$row->name[b]\n";
    $str.= "[list=disc]\n";
    $result2 = $db->query("SELECT * FROM $table->page WHERE dir='$row->id' AND language='$lang->current' ORDER BY id");
    while ($row2 = $db->nextRecord($result2))
    {
      $str.= "[*][url=$row2->id]$row2->name[/url]\n";      
    }
    $str.= getChild($row->id, $depth+1);
    $str.="[/list=disc][nl][nl]\n";
  }
  return $str;
}
?>